﻿using SolidWorks.Interop.sldworks;
using SolidWorksDll;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SolidWorksDll
{
    public partial class 属性读取与同步 : Form
    {
        public 属性读取与同步()
        {
            InitializeComponent();
        }

        private void MenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {

        }

        public bool b;
        public ModelDoc2 modelDoc;

        private void ToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            
            bool b1 = SolidWorksHelp.GetSwApp();
            var fdo = new OpenFileDialog();
            // FileDialog(msoFileDialogFilePicker)

            //打开单个文件
            fdo.Multiselect = false;
            fdo.Filter = "SolidWorks Part|*.SLDPRT|SolidWorks ASM|*.SLDASM|SolidWorks DRW|*.SLDDRW|All|*.*";//设定档案类型
            if (fdo.ShowDialog() == DialogResult.OK)
            {
                string str = fdo.FileName;
                bool b = SolidWorksHelp.OpenSwApp();
                ModelDocHelp.OpenDoc(str);

            }
            
            modelDoc = SolidWorksHelp.swApp.ActiveDoc;
            if (modelDoc != null)
            {
                
                //string[] cfgnames = modelDoc.GetConfigurationNames();
                List<Configuration> configurations = ConfigurationHelp.GetAllCfg(modelDoc);
                foreach (var item in configurations)
                {
                    Dictionary<string, string> ptyDict = new Dictionary<string, string>();
                    CustomPryHelp.GetAllPryDict(modelDoc, item.Name, ref ptyDict);

                    foreach (KeyValuePair<string, string> i in ptyDict)
                    {
                        dataGridView1.Rows.Add();
                        dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[0].Value = Path.GetFileName(fdo.FileName);
                        dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[1].Value = item.Name;
                        dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[2].Value = i.Key;
                        dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[3].Value = i.Value;

                    }
                    //string[] prynames = CustomPryMgr.GetNames();

                }


            }






           // String[] Docs =
        }
    }
}
